package com.ys.web.goods.order.controller;

import com.ys.utils.base.http.ResponseHandler;
import com.ys.utils.base.j2se.StringHandler;
import com.ys.utils.kd.Kd100Handler;
import com.ys.utils.kd.Kd100Info;
import com.ys.utils.redis.aop.RedisCache;
import com.ys.utils.redis.aop.RedisType;
import com.ys.utils.spring.config.SystemError;
import com.ys.utils.spring.properties.Config;
import com.ys.web.goods.order.model.Order;
import com.ys.web.goods.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods/order")
public class GoodsOrderController {
    @Autowired
    private OrderService orderService;
    @RequestMapping("/kd100/query")
    @RedisCache(type = RedisType.None,timeOut = 300)
    public String kd100Query(@RequestAttribute String uid,String l_id){
        if (!Boolean.parseBoolean(StringHandler.getString(Config.pp.get("goods.order.kd100.query.switch"),"true"))) {
            return ResponseHandler.error("500", "该功能已关闭");
        }
        if(StringHandler.isEmpty(l_id)){
            SystemError.wrapBs("500","参数错误");
        }
        Order order = orderService.getOrderLid(StringHandler.getLong(uid),l_id);
        if(StringHandler.isEmpty(order)){
            SystemError.wrapBs("500","该订单不存在");
        }
        Kd100Info kd100Info = Kd100Handler.Get(l_id,order.getPhone());
        return ResponseHandler.success(kd100Info);
    }
}
